package com.weixing.mall.provider.service.impl;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.provider.api.model.vo.SysUserAuthVo;
import com.weixing.mall.provider.api.service.SysUserRpcService;
import com.weixing.oauth2.common.userdetails.IUserDetailsService;
import com.weixing.oauth2.common.userdetails.SecurityUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

/**
 * @ClassName SysUserAuthServiceImpl
 * @Description
 * @Author Small
 * @Date 2019/12/24 17:18
 * @Version 1.0
 **/
@Component("customUserDetailService")
public class CustomUserDetailServiceImpl implements IUserDetailsService {
    @Autowired
    private SysUserRpcService sysUserRpcService;

    @Override
    public SecurityUser loadUserByUsername(String loginName) {
        System.out.println("进入 后台管理员userdetail service");
        Result<SysUserAuthVo> voResult = sysUserRpcService.loadUserByUserName(loginName);
        SysUserAuthVo sysUserVo = voResult.getData();
        if (null != sysUserVo){
            return new SecurityUser( sysUserVo.getLoginName(), sysUserVo.getLoginPwd());
        }
        return null;
    }

    @Override
    public SecurityUser loadUserByMobile(String mobile) {
        Result<SysUserAuthVo> voResult = sysUserRpcService.loadUserByMobile(mobile);
        SysUserAuthVo sysUserVo = voResult.getData();
        if (null != sysUserVo){
            return new SecurityUser(sysUserVo.getLoginName(), sysUserVo.getLoginPwd());
        }
        return null;
    }

    @Override
    public Collection<GrantedAuthority> loadAuthority(Long userId) {
        return null;
    }

    @Override
    public UserDetails loadUserByPhoneAndPassword(String phone, String password) {
        return null;
    }

    @Override
    public UserDetails loadUserByPhoneAndSmsCode(String phone, String smsCode) {
        return null;
    }

    @Override
    public void handlerLoginData(HttpServletRequest request, SecurityUser securityUser) {

    }
}
